package com.woniuxy.springbootthymeleaf.controller;

import com.woniuxy.springbootthymeleaf.entity.Books;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * @author linke
 * @version 1.0
 * @className: ExController
 * @description: 模板引擎表达式
 * @date 2021/11/17 0:22
 */

@Controller
@RequestMapping("ex")
public class ExController {
    /**
     * 变量表达式
     *
     * @param session 作用域一次会话
     * @return
     */
    @RequestMapping("/var")
    public String var(HttpSession session){
        session.setAttribute("book",new Books().setName("沉思录").setPrice(200));
        //
        return "/expression.html";
    }

    /**
     * URL表达式
     *  URL表达式th:href=”@{…}”
     *
     * @param map
     * @return
     */
    @RequestMapping("/url")
    public String url(ModelMap map){
        map.addAttribute("orderId","10001");
        //
        return "/urlexpression.html";
    }

    /**
     * 内联表达式：th:inline [[]]
     *
     *
     * @param map
     * @return
     */
    @RequestMapping("/inline")
    public String css(ModelMap map) {
        Map<String,Object> data = new HashMap<>();
        data.put("textColor","red");
        data.put("content","清风徐来，水波不兴");
        //
        map.addAllAttributes(data);
       /* map.addAttribute("content","清风徐来，水波不兴");
        map.addAttribute("textColor","red");*/
        //
        return "/inlineexpression.html";
    }
}
